<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: Quadrature Decoder (TCPWM)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__tcpwm__quaddec.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">API Reference</a>  </div>
  <div class="headertitle">
<div class="title">Quadrature Decoder (TCPWM)<div class="ingroups"><a class="el" href="group__group__tcpwm.html">TCPWM        (Timer Counter PWM)</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>Driver API for Quadrature Decoder. </p>
<p>The functions and other declarations used in this part of the driver are in cy_tcpwm_quaddec.h. You can also include cy_pdl.h to get access to all functions and declarations in the PDL.</p>
<p>A quadrature decoder is used to decode the output of a quadrature encoder. A quadrature encoder senses the position, velocity, and direction of an object (for example a rotating axle, or a spinning mouse ball). A quadrature decoder can also be used for precision measurement of speed, acceleration, and position of a motor's rotor, or with a rotary switch to determine user input.</p>
<p>The Quadrature Decoder has the following features:</p><ul>
<li>16- or 32-bit Counter.</li>
<li>Period Register. This is only available in TCPWM Version 2.</li>
<li>Range 0, Range 0 Compare, Range 1 capture, Range 1 Compare Quadrature modes. This is only available in TCPWM Version 2.</li>
<li>Counter Resolution of x1, x2, x4, and up/down rotary the frequency of the phiA (Count) and phiB (Start) inputs. Up/Down rotary resolution is only available in TCPWM Version 2</li>
<li>Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.</li>
<li>Index Input to determine absolute position</li>
<li>A positive edge on phiA increments the counter when phiB is 0 and decrements the counter when phiB is 1</li>
<li>Two programmable trigger outputs, trig_out0 and trig_out1 that generate a trigger on one of the following events Overflow, Underflow, Terminal Count, and Compare Match 0/1. The available triggers are dependent on the QuadDec mode. All these features are only available in TCPWM Version 2.</li>
<li>TC (cc_match) trigger output is only available in TCPWM Version 1.</li>
<li>Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.</li>
</ul>
<h1><a class="anchor" id="group_tcpwm_quaddec_configuration"></a>
Configuration Considerations</h1>
<p>The QuadDec configuration can be divided to number of sequential steps listed below:</p><ul>
<li><a class="el" href="group__group__tcpwm__quaddec.html#group_tcpwm_quaddec_config">Configure Quadrature</a></li>
<li><a class="el" href="group__group__tcpwm__quaddec.html#group_tcpwm_quaddec_clock">Assign Clock Divider</a></li>
<li><a class="el" href="group__group__tcpwm__quaddec.html#group_tcpwm_quaddec_enable">Enable Quadrature Decoder</a></li>
<li><a class="el" href="group__group__tcpwm__quaddec.html#group_tcpwm_quaddec_start">Start Quadrature Decoder</a></li>
</ul>
<h2><a class="anchor" id="group_tcpwm_quaddec_config"></a>
Configure Quadrature</h2>
<p>To configure Quadrature, provide the configuration parameters in the <a class="el" href="structcy__stc__tcpwm__quaddec__config__t.html">cy_stc_tcpwm_quaddec_config_t</a> structure. The Configuration structure can be modified through software, but if the configurator in ModusToolbox is used then the configuration structure will be updated with the users input. To initialize the driver, call <a class="el" href="group__group__tcpwm__functions__quaddec.html#gad1949f233fc99ae5681094b5f6a499bc">Cy_TCPWM_QuadDec_Init</a> function providing a pointer to the populated <a class="el" href="structcy__stc__tcpwm__quaddec__config__t.html">cy_stc_tcpwm_quaddec_config_t</a> structure.</p>
<p>For TCPWM V1 Configuration </p><div class="fragment"><div class="line">    <span class="comment">/* Scenario: there is need to initialize</span></div><div class="line"><span class="comment">     * the first (index = 0) quadrature decoder of the TCPWM0 block</span></div><div class="line"><span class="comment">     * with the below configuration settings</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    <a class="code" href="structcy__stc__tcpwm__quaddec__config__t.html">cy_stc_tcpwm_quaddec_config_t</a> tcpwm_v1_qd_config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .resolution        = */</span> <a class="code" href="group__group__tcpwm__quaddec__resolution.html#ga218c2bf6b15989e182676b70b4bff85a">CY_TCPWM_QUADDEC_X1</a>, <span class="comment">/* One count during one encoder cycle */</span></div><div class="line">        <span class="comment">/* .interruptSources  = */</span> <a class="code" href="group__group__tcpwm__interrupt__sources.html#gab5db2da5edd94851eebb473325dd6324">CY_TCPWM_INT_ON_TC</a>,  <span class="comment">/* Simple example without index input */</span></div><div class="line">        <span class="comment">/* .indexInputMode    = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* The default value (0UL) */</span></div><div class="line">        <span class="comment">/* .indexInput        = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* The index input is not used */</span></div><div class="line">        <span class="comment">/* .stopInputMode     = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* The default value (0UL) */</span></div><div class="line">        <span class="comment">/* .stopInput         = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* The stop input is not used, the block will be stopped by SW */</span></div><div class="line">        <span class="comment">/* .phiAInput         = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#gabe343e8f0821b0b0a5853f11b0da2f47">CY_TCPWM_INPUT_TRIG_0</a>, <span class="comment">/* The phiA input is connected to the trigger multiplexer #0 of the Trigger Group #3 */</span></div><div class="line">        <span class="comment">/* .phiBInput         = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#gaae060090a4a95ad4b6ae724c715effa9">CY_TCPWM_INPUT_TRIG_1</a>,  <span class="comment">/* The phiB input is connected to the trigger multiplexer #1 of the Trigger Group #3 */</span></div><div class="line">    };</div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_TCPWM_CNT_NUM   (0UL)</span></div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (<a class="code" href="group__group__tcpwm__enums.html#gga236beaba02c8a2a1c4eec981501e7270af9807d578257fa9f0d29cd86ef2c71ea">CY_TCPWM_SUCCESS</a> != <a class="code" href="group__group__tcpwm__functions__quaddec.html#gad1949f233fc99ae5681094b5f6a499bc">Cy_TCPWM_QuadDec_Init</a>(TCPWM0, MY_TCPWM_CNT_NUM, &amp;tcpwm_v1_qd_config))</div><div class="line">    {</div><div class="line">        <span class="comment">/* Handle possible errors */</span></div><div class="line">    }</div><div class="line">    <span class="comment">/* Enabled the initialized quadrature decoder */</span></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__quaddec.html#ga749543ff6e63948f009d4d67f3875b53">Cy_TCPWM_QuadDec_Enable</a>(TCPWM0, MY_TCPWM_CNT_NUM);</div><div class="line"></div><div class="line">    <span class="comment">/* Then start the decoder */</span></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__common.html#ga710f6bd4caaeda13df9c2ab91b8d1571">Cy_TCPWM_TriggerReloadOrIndex_Single</a>(TCPWM0, MY_TCPWM_CNT_NUM);</div></div><!-- fragment --><p> For TCPWM V2 Configuration </p><div class="fragment"><div class="line">    <span class="comment">/* Scenario: there is need to initialize</span></div><div class="line"><span class="comment">     * the first (index = 0) quadrature decoder of the TCPWM0 block</span></div><div class="line"><span class="comment">     * with the below configuration settings</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    <a class="code" href="structcy__stc__tcpwm__quaddec__config__t.html">cy_stc_tcpwm_quaddec_config_t</a> tcpwm_v2_qd_config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .resolution        = */</span> <a class="code" href="group__group__tcpwm__quaddec__resolution.html#ga218c2bf6b15989e182676b70b4bff85a">CY_TCPWM_QUADDEC_X1</a>, <span class="comment">/* One count during one encoder cycle */</span></div><div class="line">        <span class="comment">/* .interruptSources  = */</span> <a class="code" href="group__group__tcpwm__interrupt__sources.html#gab5db2da5edd94851eebb473325dd6324">CY_TCPWM_INT_ON_TC</a>,  <span class="comment">/* Simple example without index input */</span></div><div class="line">        <span class="comment">/* .indexInputMode    = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* The default value (0UL) */</span></div><div class="line">        <span class="comment">/* .indexInput        = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* The index input is not used */</span></div><div class="line">        <span class="comment">/* .stopInputMode     = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* The default value (0UL) */</span></div><div class="line">        <span class="comment">/* .stopInput         = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* The stop input is not used, the block will be stopped by SW */</span></div><div class="line">        <span class="comment">/* .phiAInput         = */</span> CY_TCPWM_INPUT_TRIG(0), <span class="comment">/* The phiA input is connected to the trigger multiplexer #0 of the Trigger Group #3 */</span></div><div class="line">        <span class="comment">/* .phiBInput         = */</span> CY_TCPWM_INPUT_TRIG(1),  <span class="comment">/* The phiB input is connected to the trigger multiplexer #1 of the Trigger Group #3 */</span></div><div class="line">        <span class="comment">/* .phiAInputMode     = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga6f8ffc8c36941d7d44290147032fd33b">CY_TCPWM_INPUT_LEVEL</a>, <span class="comment">/* Pass through (no edge detection) */</span></div><div class="line">        <span class="comment">/* .phiBInputMode     = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga6f8ffc8c36941d7d44290147032fd33b">CY_TCPWM_INPUT_LEVEL</a>, <span class="comment">/* Pass through (no edge detection) */</span></div><div class="line">        <span class="comment">/* .quadmode          = */</span> <a class="code" href="group__group__tcpwm__quaddec__mode.html#ga1bde5608416e3470da46565196e2f2e3">CY_TCPWM_QUADDEC_MODE_RANGE0</a>, <span class="comment">/* Quad mode */</span></div><div class="line">        <span class="comment">/* .period0           = */</span> 0UL, <span class="comment">/* Period 0 Value */</span></div><div class="line">        <span class="comment">/* .captureOnIndex    = */</span> <a class="code" href="group__group__tcpwm__quaddec__capture__mode.html#gadba620a2c63dd73dbaecaac505b65ae3">CY_TCPWM_QUADDEC_CAPTURE_ON_INDEX</a>, <span class="comment">/* Capture On Index event */</span></div><div class="line">        <span class="comment">/* .compare0          = */</span> 0Ul, <span class="comment">/* Sets the value for Compare 0 */</span></div><div class="line">        <span class="comment">/* .compareBuf0       = */</span> 0UL, <span class="comment">/* Sets the value for the buffered Compare 0 */</span></div><div class="line">        <span class="comment">/* .enableCompare0Swap = */</span> <span class="keyword">false</span>, <span class="comment">/*  If enabled, the compare 0 values are swapped on the terminal count */</span></div><div class="line">        <span class="comment">/* .compare1          = */</span> 0UL, <span class="comment">/* Sets the value for Compare 1 */</span></div><div class="line">        <span class="comment">/* .compareBuf1       = */</span> 0UL, <span class="comment">/* Sets the value for the buffered Compare 0 */</span></div><div class="line">        <span class="comment">/* .enableCompare1Swap = */</span> <span class="keyword">false</span>, <span class="comment">/*  If enabled, the compare 0 values are swapped on the terminal count */</span></div><div class="line">        <span class="comment">/* .capture0OrIndex1InputMode = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* Configures how the capture0/index1 input behaves.*/</span></div><div class="line">        <span class="comment">/* .capture0OrIndex1Input = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* Selects which input the capture0/index1 uses. The inputs are device-specific. */</span></div><div class="line">        <span class="comment">/* .capture1InputMode = */</span> <a class="code" href="group__group__tcpwm__input__modes.html#ga0e441e0d42e07a5bffa0e0d4e9058a26">CY_TCPWM_INPUT_RISINGEDGE</a>, <span class="comment">/* Configures how the capture1 input behaves. */</span></div><div class="line">        <span class="comment">/* .capture1Input     = */</span> <a class="code" href="group__group__tcpwm__input__selection.html#ga86b8267d250e656f6e79fbd703bce944">CY_TCPWM_INPUT_0</a>, <span class="comment">/* Selects which input the capture1 uses. The inputs are device-specific. */</span></div><div class="line">        <span class="comment">/* .trigger0Event     = */</span> <a class="code" href="group__group__tcpwm__output__trigger__modes.html#ga80297cac01044cbf8ea2af92c902da7e">CY_TCPWM_CNT_TRIGGER_ON_DISABLED</a>, <span class="comment">/* Disable output trigger0 event generation*/</span></div><div class="line">        <span class="comment">/* .trigger1Event     = */</span> <a class="code" href="group__group__tcpwm__output__trigger__modes.html#ga80297cac01044cbf8ea2af92c902da7e">CY_TCPWM_CNT_TRIGGER_ON_DISABLED</a>, <span class="comment">/* Disable output trigger1 event generation*/</span></div><div class="line">    };</div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_TCPWM_CNT_NUM   (0UL)</span></div><div class="line">    </div><div class="line">    <span class="keywordflow">if</span> (<a class="code" href="group__group__tcpwm__enums.html#gga236beaba02c8a2a1c4eec981501e7270af9807d578257fa9f0d29cd86ef2c71ea">CY_TCPWM_SUCCESS</a> != <a class="code" href="group__group__tcpwm__functions__quaddec.html#gad1949f233fc99ae5681094b5f6a499bc">Cy_TCPWM_QuadDec_Init</a>(TCPWM0, MY_TCPWM_CNT_NUM, &amp;tcpwm_v2_qd_config))</div><div class="line">    {</div><div class="line">        <span class="comment">/* Handle possible errors */</span></div><div class="line">    }</div><div class="line">    <span class="comment">/* Enabled the initialized quadrature decoder */</span></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__quaddec.html#ga749543ff6e63948f009d4d67f3875b53">Cy_TCPWM_QuadDec_Enable</a>(TCPWM0, MY_TCPWM_CNT_NUM);</div><div class="line">    </div><div class="line">    <span class="comment">/* Then start the decoder */</span></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__common.html#ga710f6bd4caaeda13df9c2ab91b8d1571">Cy_TCPWM_TriggerReloadOrIndex_Single</a>(TCPWM0, MY_TCPWM_CNT_NUM);</div></div><!-- fragment --> <h2><a class="anchor" id="group_tcpwm_quaddec_clock"></a>
Assign Clock Divider</h2>
<p>The clock source must be connected to proper working. Any of the peripheral clock dividers could be used. Use the <a class="el" href="group__group__sysclk.html">SysClk (System Clock)</a> driver API to do that.</p>
<h2><a class="anchor" id="group_tcpwm_quaddec_enable"></a>
Enable Quadrature Decoder</h2>
<p>Quadrature has to be enabled before starting</p>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Enable Quadrature Decoder */</span></div><div class="line"><span class="preprocessor">    #define MY_TCPWM_QUADDEC_NUM   (0UL)</span></div><div class="line"></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__quaddec.html#ga749543ff6e63948f009d4d67f3875b53">Cy_TCPWM_QuadDec_Enable</a>(TCPWM0, MY_TCPWM_QUADDEC_NUM);</div></div><!-- fragment --> <h2><a class="anchor" id="group_tcpwm_quaddec_start"></a>
Start Quadrature Decoder</h2>
<p>Quadrature has to be started</p>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Start Quadrature Decoder operation */</span></div><div class="line"><span class="preprocessor">    #define MY_TCPWM_QUADDEC_NUM   (0UL)</span></div><div class="line"></div><div class="line">    <a class="code" href="group__group__tcpwm__functions__common.html#ga710f6bd4caaeda13df9c2ab91b8d1571">Cy_TCPWM_TriggerReloadOrIndex_Single</a>(TCPWM0, MY_TCPWM_QUADDEC_NUM);</div></div><!-- fragment --><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
API Reference</h2></td></tr>
<tr class="memitem:group__group__tcpwm__macros__quaddec"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tcpwm__macros__quaddec.html">Macros</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tcpwm__functions__quaddec"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tcpwm__functions__quaddec.html">Functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tcpwm__data__structures__quaddec"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tcpwm__data__structures__quaddec.html">Data Structures</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
